var helangSearch = {
    els: {},
    searchIndex: 0,
    hot: {
        id: [],
        color: ['#ff2c00', '#ff5a00', '#ff8105', '#fd9a15', '#dfad1c'],
        list: [],
    },
    init: function () {
        var _this = this;
        this.els = {
            pickerBtn: $(".picker"),
            pickerList: $(".picker-list"),
            logo: $(".logo"),
            hotList: $(".hot-list"),
            input: $("#search-input"),
        };
        this.els.hotList.html(function () {
            var str = '';
            var searchArr = [1, 0];
            $.each(_this.hot.list, function (index, item) {
                str += '<a href="/search/?types=' + searchArr[_this.searchIndex] + '&content=' + item + '" target="_blank">'
                    + '<div class="number" style="color: ' + _this.hot.color[index] + '">' + (index + 1) + '</div>'
                    + '<div>' + item + '</div>'
                    + '</a>';
            });
            return str;
        });
        this.els.pickerBtn.click(function () {
            if (_this.els.pickerList.is(':hidden')) {
                setTimeout(function () {
                    _this.els.pickerList.show();
                }, 100);
            }
        });
        this.els.pickerList.on("click", ">li", function () {
            _this.searchIndex = $(this).index();
            _this.els.pickerBtn.html($(this).html())
        });
        this.els.input.click(function () {
            if (!$(this).val()) {
                setTimeout(function () {
                    _this.els.hotList.show();
                }, 100);
            }
        });
        this.els.input.on("input", function () {
            if ($(this).val()) {
                _this.els.hotList.hide();
            }
        });
        $(document).click(function () {
            _this.els.pickerList.hide();
            _this.els.hotList.hide();
        });
    },
};
$(function () {
    helangSearch.init();
    $(".search").click(function () {
        var types = 0;
        if ($('.picker').text().indexOf("图片") != -1)
            types = 1;
        window.location.href = '/search/?types=' + types + '&content=' + helangSearch.els.input.val()
    });
});
